<?php

/**
 * 封装投票项目数据缓存
 * Enter description here ...
 * @author codetaste
 *
 */

class UserGolds{
	
	private $User;
	
	private $params = 0;
	
	public function __construct($user, $params){
		$this->User = $user;
		$this->params = $params;
	}
	
	public function save(){
		$_udata['u_golds'] = $this->User->u_golds + $this->params['reg_gold'];
		
		M('User')->where(array('u_id'=>$this->User->u_id))->data($_udata)->save();
		unset($_udata);
		$this->_record();
	}
	
	private function _record(){
		$record = new recordGolds($this->User->u_id, $this->params);
		$record->save();
	}
	
}

class recordGolds{
	
	private $u_id;
	
	private $reg_glod = 0;
	
	private $reg_time;
	
	private $reg_description;
	
	private $reg_key;
	
	public function __construct($u_id, $params){
		$this->u_id = $u_id;
		$this->reg_gold = $params['reg_gold'];
		$this->reg_time = time();
		$this->reg_description = $params['reg_description'];
		$this->reg_key = $params['reg_key'];
	}
	
	public function save(){
		$_regdata = array('u_id' => $this->u_id,
						 'reg_glod' => $this->reg_gold,
						 'reg_time' => $this->reg_time,
						 'reg_description' => $this->reg_description,
						 'reg_key' => $this->reg_key );
		
		D('Record')->onAdd('Gold', $_regdata);
	}
	
}


	
	